package com.xiaoxiong.mami.dao.mapper;

import com.xiaoxiong.mami.dao.daomain.Goods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface GoodsMapper {
    @Delete({
        "delete from goods",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into goods (id, goodsId, ",
        "title, price, goodsDesc, ",
        "images, thumbUrl, ",
        "sort, status, goodsImages, ",
        "stock, buyNumMax, ",
        "goodsNumber, updateTime, ",
        "createTime)",
        "values (#{id,jdbcType=BIGINT}, #{goodsId,jdbcType=VARCHAR}, ",
        "#{title,jdbcType=VARCHAR}, #{price,jdbcType=DOUBLE}, #{goodsDesc,jdbcType=VARCHAR}, ",
        "#{images,jdbcType=VARCHAR}, #{thumbUrl,jdbcType=VARCHAR}, ",
        "#{sort,jdbcType=INTEGER}, #{status,jdbcType=VARCHAR}, #{goodsImages,jdbcType=VARCHAR}, ",
        "#{stock,jdbcType=INTEGER}, #{buyNumMax,jdbcType=INTEGER}, ",
        "#{goodsNumber,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(Goods record);

    @InsertProvider(type=GoodsSqlProvider.class, method="insertSelective")
    int insertSelective(Goods record);

    @Select({
        "select",
        "id, goodsId, title, price, goodsDesc, images, thumbUrl, sort, status, goodsImages, ",
        "stock, buyNumMax, goodsNumber, updateTime, createTime",
        "from goods",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="goodsId", property="goodsId", jdbcType=JdbcType.VARCHAR),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.DOUBLE),
        @Result(column="goodsDesc", property="goodsDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="images", property="images", jdbcType=JdbcType.VARCHAR),
        @Result(column="thumbUrl", property="thumbUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="sort", property="sort", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.VARCHAR),
        @Result(column="goodsImages", property="goodsImages", jdbcType=JdbcType.VARCHAR),
        @Result(column="stock", property="stock", jdbcType=JdbcType.INTEGER),
        @Result(column="buyNumMax", property="buyNumMax", jdbcType=JdbcType.INTEGER),
        @Result(column="goodsNumber", property="goodsNumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="updateTime", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="createTime", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Goods selectByPrimaryKey(Long id);

    @UpdateProvider(type=GoodsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Goods record);

    @Update({
        "update goods",
        "set goodsId = #{goodsId,jdbcType=VARCHAR},",
          "title = #{title,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=DOUBLE},",
          "goodsDesc = #{goodsDesc,jdbcType=VARCHAR},",
          "images = #{images,jdbcType=VARCHAR},",
          "thumbUrl = #{thumbUrl,jdbcType=VARCHAR},",
          "sort = #{sort,jdbcType=INTEGER},",
          "status = #{status,jdbcType=VARCHAR},",
          "goodsImages = #{goodsImages,jdbcType=VARCHAR},",
          "stock = #{stock,jdbcType=INTEGER},",
          "buyNumMax = #{buyNumMax,jdbcType=INTEGER},",
          "goodsNumber = #{goodsNumber,jdbcType=VARCHAR},",
          "updateTime = #{updateTime,jdbcType=TIMESTAMP},",
          "createTime = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Goods record);
}